package com.example.firebase.test;

import com.alibaba.fastjson.JSONObject;
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.Notification;
import org.junit.Test;

/**
 * @Description :
 * @Author : ls 2021/1/4 16:41
 * @Modified : ls 2021/1/4
 */
public class demo {


    @Test
    public void testFireBase() {
        JSONObject json = new JSONObject();
        json.put("channelId",1);
        json.put("scheduleId",1);
        String topicName="11";
        Integer id = 0;
        MessagePush messagePush = new MessagePush();
        messagePush.setTitle("测试标题");
        messagePush.setContent("测试内容");
        Message notificationMessage = null;
        //标题，内容
        Notification notification = new Notification(messagePush.getTitle(), messagePush.getContent());
        notificationMessage = Message.builder()
                .setNotification(notification)
                /*//其他数据
                .putData("messageId", String.valueOf(id))
                .putData("type", "live")
                .putData("channelId", json.getString("channelId"))
                .putData("scheduleId", json.getString("scheduleId"))
                //主题*/
                .setTopic(topicName)
                .build();

        String sendResp = null;
        try {
            sendResp = FireBaseUtil.sendTopicMessage(notificationMessage);
            System.out.println("sendResp:"+sendResp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
